package lib

import (
	"fmt"
	"strings"

	"github.com/PuerkitoBio/goquery"
)

func GetQiKe() (lists map[string]string) {
	resp, err := HttpGet("https://www.solidot.org/")
	if err != nil {
		fmt.Printf("err: %v\n", err)
	}
	defer resp.Body.Close()
	doc, err := goquery.NewDocumentFromReader(resp.Body)
	if err != nil {
		fmt.Printf("err: %v\n", err)
	}
	lists = make(map[string]string)
	doc.Find("#center .block_m").Each(func(i int, s *goquery.Selection) {
		title := s.Find(".bg_htit h2").Text()
		title = strings.ReplaceAll(title, "\n", "")
		title = strings.ReplaceAll(title, " ", "")
		content := s.Find(".p_content .p_mainnew").Text()
		content = strings.ReplaceAll(content, "\n", "")
		content = strings.TrimLeft(content, " ")
		if i < 5 {
			lists[title] = content
		}
	})
	return
}
